﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ApplyPathTemplateAction.CApApplyPathTemplateActionValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.ApplyPathTemplateAction;

internal class CApApplyPathTemplateActionValidator : ITxValidator
{
  private IPathTemplateData m_data;
  private bool m_allowComponenets;

  internal TxRobot Robot => this.m_data.Robot;

  public CApApplyPathTemplateActionValidator(IPathTemplateData data, bool allowComponenets = false)
  {
    this.m_allowComponenets = allowComponenets;
    this.m_data = data;
  }

  public ITxObject GetObject(string str)
  {
    ITxObject itxObject1 = (ITxObject) null;
    TxObjectList txObjectList = (TxObjectList) null;
    if (!string.IsNullOrEmpty(str))
      txObjectList = TxApplication.ActiveDocument.GetObjectsByName(str);
    if (txObjectList != null && ((Collection<ITxObject>) txObjectList).Count > 0)
    {
      foreach (ITxObject itxObject2 in (Collection<ITxObject>) txObjectList)
      {
        if (this.ValidObjectType(itxObject2))
        {
          itxObject1 = itxObject2;
          break;
        }
      }
    }
    return itxObject1;
  }

  public string GetText(ITxObject obj)
  {
    string text = string.Empty;
    if (obj != null)
      text = obj.Name;
    return text;
  }

  private bool ValidObjectType(ITxObject obj)
  {
    bool flag = false;
    if (!this.m_allowComponenets)
    {
      switch (obj)
      {
        case ITxWeldOperation _:
        case TxGenericRoboticOperation _:
        case ITxContinuousOperation _:
        case TxRoboticSeamOperation _:
        case TxCompoundOperation _:
          flag = true;
          break;
      }
    }
    else
    {
      switch (obj)
      {
        case Tx2Or3DimensionalGeometry _:
        case TxComponent _:
          flag = true;
          break;
      }
    }
    return flag;
  }

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    bool flag = false;
    errorMessage = (string) null;
    if (this.ValidObjectType(obj))
    {
      if (!this.m_allowComponenets)
      {
        TxRobot robot = new CApApplyPathTemplateUtil().GetRobot(obj as ITxOperation);
        if (TxRobot.op_Inequality(robot, (ITxObject) null))
        {
          if (TxRobot.op_Equality(this.Robot, (ITxObject) robot))
            flag = true;
          else if (TxRobot.op_Equality(this.Robot, (ITxObject) null))
            flag = true;
        }
      }
      else
        flag = true;
    }
    if (!flag)
      errorMessage = PathTemplateActionStringTable.INVALID_OPERATION;
    return flag;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    errorMessage = string.Empty;
    bool flag = false;
    ITxObject itxObject = this.GetObject(text);
    if (itxObject == null)
      errorMessage = PathTemplateActionStringTable.INVALID_OPERATION;
    else
      flag = this.IsValidObject(itxObject, out errorMessage);
    return flag;
  }
}
